<?php
class LookupValuesController extends AppController {
    var $name = 'LookupValues';

    function index() {
        $this->LookupValue->recursive = 0;
        $this->set('lookupValues', $this->paginate());
    }

    function view($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid lookup value', true));
            $this->redirect(array('action' => 'index'));
        }
        $this->set('lookupValue', $this->LookupValue->read(null, $id));
    }

    function add() {
        if (!empty($this->data)) {
            $this->LookupValue->create();
            $this->data['LookupValue']['end_date'] = null;
            if ($this->LookupValue->save($this->data)) {
                $this->Session->setFlash(__('The lookup value has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The lookup value could not be saved. Please, try again.', true));
            }
        }
    }

    function edit($id = null) {
        if (!$id && empty($this->data)) {
            $this->Session->setFlash(__('Invalid lookup value', true));
            $this->redirect(array('action' => 'index'));
        }
        if (!empty($this->data)) {
            if ($this->LookupValue->save($this->data)) {
                $this->Session->setFlash(__('The lookup value has been saved', true));
                $this->redirect(array('action' => 'index'));
            } else {
                $this->Session->setFlash(__('The lookup value could not be saved. Please, try again.', true));
            }
        }
        if (empty($this->data)) {
            $this->data = $this->LookupValue->read(null, $id);
        }
    }

    function delete($id = null) {
        if (!$id) {
            $this->Session->setFlash(__('Invalid id for lookup value', true));
            $this->redirect(array('action'=>'index'));
        }
        if (empty($this->data)) {
            $this->data = $this->LookupValue->read(null, $id);
        }
        if (!empty($this->data)) {
            // ACA SETEO EL UPDATED_BY
            $this->data['LookupValue']['end_date'] = date('Y-m-d H:i:s');
            if ($this->LookupValue->save($this->data)) {
                $this->Session->setFlash(__('Lookup value deleted', true));
            } else {
                $this->Session->setFlash(__('Lookup value was not deleted', true));
            }
        }
        $this->redirect(array('action' => 'index'));
    }
}
?>